package dao.impl;

import dao.AccountDao;
import entity.Account;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionUtil;

public class AccountDaoImpl implements AccountDao {
    private SqlSession sqlSession;
    @Override
    public int insert(Account account){
        sqlSession = SqlSessionUtil.getSqlSession();
        int result = sqlSession.insert("AccountMapper.insert",account);
        sqlSession.close();
        return result;
    }

    @Override
    public int delete(int id){
        sqlSession = SqlSessionUtil.getSqlSession();
        int result = sqlSession.delete("AccountMapper.delete",id);
        sqlSession.close();
        return result;
    }

    @Override
    public int update(Account account){
        sqlSession = SqlSessionUtil.getSqlSession();
        int result = sqlSession.update("AccountMapper.update",account);
        sqlSession.close();
        return result;
    }

    @Override
    public Account getOne(int id){
        sqlSession = SqlSessionUtil.getSqlSession();
        Account account = sqlSession.selectOne("AccountMapper.getOne",id);
        sqlSession.close();
        return account;
    }

    @Override
    public Account exist(Account account){
        sqlSession = SqlSessionUtil.getSqlSession();
        account = sqlSession.selectOne("AccountMapper.exist",account);
        sqlSession.close();
        return account;
    }

}
